package com.tg.app.helper;

import android.app.Activity;
import android.content.Intent;
import android.content.IntentFilter;
import androidx.annotation.NonNull;
import com.tg.app.HomeWatcherReceiver;

public class HomeKeyHelper {
    private HomeWatcherReceiver mReceiver;
    public void registerHomeKeyReceiver(@NonNull Activity activity, HomeWatcherReceiver.HomeKeyHelperListener homeKeyHelperListener) {
        mReceiver = new HomeWatcherReceiver();
        mReceiver.setHomeKeyHelperListener(homeKeyHelperListener);
        IntentFilter homeFilter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
        activity.registerReceiver(mReceiver, homeFilter);
    }

    public void unregisterHomeKeyReceiver(@NonNull Activity activity) {
        if (mReceiver != null) {
            activity.unregisterReceiver(mReceiver);
            mReceiver = null;
        }
    }
}
